package net.xiduth.game.player.dialogues;

import net.xiduth.game.World;
import net.xiduth.game.player.Skills;

/**
 * 
 * @author Plato
 * 
 */

public class Max extends Dialogue {

	int npcId;

	@Override
	public void start() {
		npcId = (Integer) parameters[0];
		if (Skills.getTotalLevel(player) < 2279) {
			sendNPCDialogue(
					npcId,
					9827,
					"You are not yet eligiable for this cape, "
							+ player.getDisplayName() + ".");
			stage = -2;
		} else {
			sendNPCDialogue(npcId, 9827, "How can I help you?");
		}
	}

	@Override
	public void run(int interfaceId, int componentId) {
		switch (stage) {
		case -1:
			sendPlayerDialogue(9827, "Who are you?");
			stage = 1;
			break;
		case 1:
			sendNPCDialogue(npcId, 9827, "A good question. My name is Max.");
			stage = 2;
			break;
		case 2:
			sendNPCDialogue(npcId, 9827,
					"I reward those who are maxed with this cape I am wearing.");
			stage = 3;
			break;
		case 3:
			sendPlayerDialogue(9827,
					"Nice to meet you max. I was actually wondering what that cape is for?");
			stage = 4;
			break;
		case 4:
			sendNPCDialogue(npcId, 9827,
					"This cape is a symbol that I have trained all of my skills to level 99.");
			stage = 5;
			break;
		case 5:
			sendPlayerDialogue(9827, "So have I!");
			stage = 6;
			break;
		case 6:
			sendNPCDialogue(
					npcId,
					9827,
					"Indeed you have, "
							+ player.getDisplayName()
							+ ". Would you like to buy this cape? 2,475,000 coins - 99,000 coins for each skill!");
			stage = 7;
			break;
		case 7:
			sendPlayerDialogue(9827, "I'll take one!");
			stage = 8;
			break;
		case 8:
			if (player.getMoneyInPouch() < 2475000) {
				sendNPCDialogue(npcId, 9827,
						"Please come back when you have enough coins.");
				stage = -2;
			} else if (player.getInventory().getFreeSlots() < 2) {
				sendNPCDialogue(npcId, 9827,
						"Sorry, but your inventory seems to be full, please come back with more space.");
				stage = -2;
			} else {
				int value = 2475000;
				player.getMoneyPouch().remove(value);
				player.getInventory().deleteItem(995, 2475000);
				player.getInventory().addItem(20768, 1);
				player.getInventory().addItem(20767, 1);
				sendNPCDialogue(npcId, 9827, "Congratulations!");
				if (Skills.getTotalLevel(player) >= 1000 && player.isMaxed == 0) {
					player.isMaxed = 1;
					World.sendWorldMessage(
							"<col=ff8c38><img=7>News: "
									+ player.getDisplayName()
									+ " has just been awarded the Max Cape!"
									+ "</col> ", false);
				}
				stage = -2;
			}
			break;
		case -2:
			end();
			break;
		}
	}

	@Override
	public void finish() {

	}
}